package first.codeTop.meituan;


public class Leetcode22 {
    // 链表中的倒数第k个节点
    public static void main(String[] args) {

    }

    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode node = head;
        int sum = 0;
        while (node != null) {
            sum++;
            node = node.next;
        }
        int flag = sum-k;

        while (flag != 0) {
            head = head.next;
            flag--;
        }

        return head;
    }

    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }
}
